package com.mall.server.controller;

import com.mall.commons.R;
import com.mall.commons.exceotion.BusinessException;
import com.mall.commons.exceotion.ErrorResult;
import com.mall.server.service.OrderService;
import com.tanhua.model.dto.OrderDto;
import com.tanhua.model.dto.OrderIdAllDto;
import com.tanhua.model.dto.ReceiverDto;
import com.tanhua.model.dto.UpdatedeliveryDto;
import com.tanhua.model.vo.PageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 查询订单
     *
     * @param orderDto
     * @return
     */
    @GetMapping("/list")
    public R listOmsOrder(OrderDto orderDto) {

        PageVo pageVo = orderService.listOmsOrder(orderDto);
        if (pageVo == null) {
            throw new BusinessException(ErrorResult.emptyError());
        }
        return R.success(pageVo);
    }

    /**
     * 获取订单详情：订单信息、商品信息、操作记录
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public R getById(@PathVariable Integer id) {
        OrderIdAllDto dto = orderService.getById(id);
        return R.success(dto);
    }

    /*
     */
/**
 * 批量发货
 *
 * @param omsOrder
 * @return
 *//*

    @PostMapping("/update/delivery")
    public R upodates(@RequestBody OmsOrder omsOrder) {
        orderService.upodates(omsOrder);
        return R.success("操作成功");
    }
*/


    /**
     * 备注订单
     *
     * @param id
     * @param note
     * @param status
     * @return
     */
    @PostMapping("/update/note")
    public R updateNote(Integer id, String note, Integer status) {
        orderService.updateNote(id, note, status);
        return R.success("操作成功");
    }


    /**
     * 修改收货人信息
     *
     * @param dto
     * @return
     */
    @PostMapping("/update/receiverInfo")
    public R updateReceiverInfo(@RequestBody ReceiverDto dto) {
        orderService.updateReceiverInfo(dto);
        return R.success("操作成功");
    }

    /**
     * 批量发货
     *
     * @param dto
     * @return
     */
    @PostMapping("/update/delivery")
    public R updateDeliveryo(@RequestBody UpdatedeliveryDto[] dto) {
        orderService.updateDeliveryo(dto);
        return R.success("操作成功");
    }

    /**
     * 批量删除订单
     *
     * @param ids
     * @return
     */
    @PostMapping("/delete")
    public R deletesw(Integer[] ids) {
        orderService.deletesw(ids);
        return R.success("操作成功");
    }


}
